package cn.yza.Kotlin.test

/**
@author Honglixi
@create 2022-06-02 14:19
 */
class User(val id: Int, val name: String, val address: String)
fun saveUser(user: User) {
    fun validate(user: User,
                 value: String,
                 fieldName: String) {
        if (value.isEmpty()) {
            throw Exception("Can`t save user ${user.id}: empty $fieldName")
        }
    }
}
fun User.validateBeforeSave() {
    fun validate(value: String, fieldName: String) {
        if (value.isEmpty()) {
            throw Exception("Can`t save user ${id}: empty $fieldName")
        }
    }
    validate(name, "Name")
    validate(address, "Address")

}
fun save(user: User) {
    user.validateBeforeSave()
}
fun main() {
//    User user = new User
//    save()
}